package com.sicau.basedemo.generator;

import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.generator.AutoGenerator;
import com.baomidou.mybatisplus.generator.config.DataSourceConfig;
import com.baomidou.mybatisplus.generator.config.GlobalConfig;
import com.baomidou.mybatisplus.generator.config.PackageConfig;
import com.baomidou.mybatisplus.generator.config.StrategyConfig;
import com.baomidou.mybatisplus.generator.config.rules.NamingStrategy;

/**
 * @author sxt
 */
public class CodeGenerator {

    public static void main(String[] args) {

        // 代码生成器
        AutoGenerator mpg = new AutoGenerator();

//        全局配置
        GlobalConfig globalConfig = new GlobalConfig();
//        globalConfig.setOutputDir(System.getProperty("user.dir") + "/src/main/java");
        globalConfig.setOutputDir("/Users/sxt/Downloads/test");
        globalConfig.setAuthor("sxt && ttxxi");
        globalConfig.setOpen(true);
        globalConfig.setIdType(IdType.AUTO);
        globalConfig.setServiceName("%sService");
        globalConfig.setSwagger2(true);

        mpg.setGlobalConfig(globalConfig);

//        数据源配置
        DataSourceConfig dataSourceConfig = new DataSourceConfig();
        dataSourceConfig.setUrl("jdbc:mysql://localhost:3306/base_demo?useUnicode=true&useSSL=false&characterEncoding=utf8&useTimezone=true&serverTimezone=GMT%2B8");
        dataSourceConfig.setDriverName("com.mysql.cj.jdbc.Driver");
        dataSourceConfig.setUsername("root");
        dataSourceConfig.setPassword("123456");

        mpg.setDataSource(dataSourceConfig);

        // 包配置
        PackageConfig pc = new PackageConfig();
//        pc.setModuleName("");
        pc.setParent("com.sicau.basedemo");
//        pc.setXml("mapper");
        mpg.setPackageInfo(pc);

        // 策略配置
        StrategyConfig strategy = new StrategyConfig();
        strategy.setNaming(NamingStrategy.underline_to_camel);
        strategy.setColumnNaming(NamingStrategy.underline_to_camel);
        strategy.setEntityLombokModel(true);
        strategy.setRestControllerStyle(true);


        strategy.setInclude((
//                "clazz," +
//                "college," +
//                "grade," +
//                "points," +
//                "points_exchange," +
//                "points_item," +
//                "practice_news," +
//                "practice_type," +
//                "prize," +
//                "team," +
//                "team_instruction," +
//                "team_member," +
                "user").split(","));


        strategy.setControllerMappingHyphenStyle(true);

        mpg.setStrategy(strategy);
        mpg.execute();
    }

}
